﻿using Microsoft.AspNetCore.Mvc;
using Project.Ycm20250401.Service._20250407;
using Project.Ycm20250401.Service._20250409;

namespace Project.Ycm20250401.Net.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class OrdersController : ControllerBase
    {
        private readonly OrderManager _orderManager;

        public OrdersController(OrderManager orderManager)
        {
            _orderManager = orderManager;
        }

        [HttpPost]
        public async Task<IActionResult> PlaceOrder([FromBody] Order20250409 order)
        {
            if (order == null || string.IsNullOrEmpty(order.CustomerEmail))
            {
                return BadRequest("Invalid order data.");
            }

            await _orderManager.PlaceOrderAsync(order);

            return Ok(new { Message = "Order placed successfully.", OrderId = order.OrderId });
        }
    }
}
